import request from "@/utils/request";
import {serverIp} from "../../public/config.js";
const API_BASE_URL = `http://${serverIp}:8081/jdyfy`;

/**
 * 公告相关API请求
 */

/**
 * 添加公告
 * @param form
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addAnnouncement = (form) =>{
    return request.post(`${API_BASE_URL}/announcement/save`, form)
        .then(res => {
            return res;
        })
};

/**
 * 通过项目编号的集合去获取每个项目对应公告
 * @returns {Promise<axios.AxiosResponse<any>>}
 * @param projects
 */
export const getAnnouncementsByProjectNumbers  = (projects) =>{
    return request.post(`${API_BASE_URL}/getAnnouncements`,projects).then(res => {
        return res;
    })
}

/**
 * 获取报名部门数量
 * @param announcementNames
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getEnlistDepartmentCount  = (announcementNames) =>{
    return request.post(`${API_BASE_URL}/getEnlistsDepartment`,announcementNames).then(res => {
        return res;
    })
}

/**
 * 根据公告名称获取报名企业
 * @param announcementName
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getEnlistDepartments  = (announcementName) =>{
    return request.post(`${API_BASE_URL}/getEnlistsDepartments`,announcementName).then(res => {
        return res;
    })
}

/**
 * 根据部门名称获取报名公告
 * @param pageNum
 * @param pageSize
 * @param departmentName
 * @param projectName
 * @param projectNumber
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getEnlistAnnouncementsBydepartment  = (pageNum, pageSize,departmentName,projectName,projectNumber) =>{
    return request.get(`${API_BASE_URL}/getEnlistsAnnouncementsBydepartment`,{
        params: {
            pageNum,
            pageSize,
            departmentName,
            projectName,
            projectNumber,
        }
        }).then(res => {
        return res.data;
    })
}

/**
 * 通过公告名称查询公告
 * @param announcementName
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAnnouncementByName = (announcementName) => {
    return request.get(`${API_BASE_URL}/announcement/findByName`, {params: {announcementName}})
        .then(res => {
            return res.data;
        })
};

/**
 * 通过公告名称查询公告
 * @param name
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getAnnoByName = (name) => {
    return request.get(`${API_BASE_URL}/announcement/findByName`, {params: {name}})
        .then(res => {
            return res.data;
        })
};


export const getAdIsHave = (announcementName,departmentName) => {
    return request.get(`${API_BASE_URL}/ad/getByadName`, {params: {announcementName,departmentName}})
        .then(res => {
            return res.data;
        })
};